<?php 

    session_start();
    function getParam($name){
        $value = isset($_GET[$name])?trim($_GET[$name]):"";
        $value = str_replace("'","''",$value);
        return $value;
    }


    $requestMethod = $_SERVER["REQUEST_METHOD"];
    if($requestMethod=="GET"){
            $id = getParam("Id");

    $sql = "select * from `article` where Id=$id";  
    $conn = new mysqli("localhost","root","","mybolg");
    $rs = $conn->query($sql);
    if($conn->error) die($conn->error);
    $detail = $rs->fetch_assoc();
    }else{
        $id = getParam("id");
        $title = $_POST["Title"];
        $content = $_POST["Content"];
        $updateTime=date_format(new DateTime(),"Y-m-d H:i:s");
        $sql = "UPDATE `article` SET `Title`='$title',`Content`='$content',`UpdateTime`='$updateTime' where Id=$id";
        $conn = new mysqli("localhost","root","","mybolg");
        $rs = $conn->query($sql);
        if($conn->error) die($conn->error);
        Header("Location: art_list.php");
        die("ok");
    }



?>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
            <title></title>
        </head>
        <body>
            <form method="POST" action="article_modify.php?id=<?=$id ?>">
            <div>
                <label>
                    标题
                </label>
                <input type="text" name="Title" value="<?=$detail["Title"]?>"/>
            </div>
            <div>
                <label>
                    内容
                </label>
                <textarea name="Content" ><?=$detail["Content"]?></textarea>
            </div>
            <div>
                <?=$detail["AuthorName"]?>编辑于
                <?=$detail["UpdateTime"]?>
            </div>
            <div>
                <input type="submit" value="提交" />
                <a href="article_list.php">返回列表</a>
            </div>
        </form>
        </body>
    </html>